package fr.ginvest.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity
@Table(name = "investisseur_angel")
@DiscriminatorValue("A")
public class Angel extends Investisseur implements Serializable {

	private static final long serialVersionUID = 8166333531557348906L;
	
	@OneToOne(mappedBy="president")
	private Club myClub = null;
	
	@ManyToMany(mappedBy="membres", fetch=FetchType.EAGER)
	private Set<Club> clubs = new HashSet<Club>();
	
	@OneToMany(mappedBy="origine")
	private Set<DemandeAngelClub> demandes = new HashSet<DemandeAngelClub>();

	public Angel() {}
	
	public Angel(String login, String motDePasse, int fondPropre,
			String nom, String prenom) {
		super(login, nom, prenom, motDePasse, fondPropre);
	}

	public Collection<Club> getClubs() {
		return clubs;
	}

	public Collection<DemandeAngelClub> getDemandes() {
		return demandes;
	}

	public void setDemandes(Set<DemandeAngelClub> demandes) {
		this.demandes = demandes;
	}

	public void addDemande(DemandeAngelClub demande) {
		this.demandes.add(demande);
	}

	public Club getMyClub() {
		return myClub;
	}

	public void setMyClub(Club myClub) {
		this.myClub = myClub;
	}
	
	public boolean isPresidentof(Club club) {
		if(club==null || myClub == null)
			return false;
		else
			return myClub.getId()==club.getId();
	}
	
	public boolean isMemberOf(Club club) {
		return this.clubs.contains(club);
//		for(Club c: clubs){
//			if(c.equals(club))
//				return true;
//		}
//		return false;
	}
}
